Branching Strategies
Branch nima?
Branch - bu kodingizning "shoxchasi". Bu main koddan alohida ravishda ishlash imkonini beradi.
Misol uchun:
main ──────●──────●──────────●──────●
\ /
feature ●──────●──────●
Nima uchun Branch kerak?
Muammolar branch'siz:
- Bir necha kishi bir vaqtda ishlaganda kod chalkashadi
- Yangi feature ustida ishlayotganda main kod buzilishi mumkin
- Xatolarni tuzatish qiyin
- Release qilish tartibsiz
Branch bilan:
- Har bir vazifa uchun alohida branch
- Main kod doimo ishlaydigan holatda
- Parallel ishlash mumkin
- Xavfsiz experiment qilish
Asosiy Branch Commands
# Barcha branch larni ko'rish
git branch
# Yangi branch yaratish
git branch feature/login
# Branch ga o'tish
git checkout feature/login
# Yaratish va o'tish (bir buyruqda)
git checkout -b feature/login
# Branch ni o'chirish
git branch -d feature/login
# Remote branch larni ko'rish
git branch -r
Asosiy Branching Strategiyalar
1. Git Flow
Bu - eng mashhur va keng tarqalgan strategiya.
Branch lar:
main (production) ●──────●──────●──────●
\ /
develop (development) ●──●──●──●──●──●
\ | | | /
feature/login ●─● | |
feature/payment ●─● |
hotfix/critical-bug ●─●
Branch lari:
- main - Production kodlar (faqat stable)
- develop - Development kodlar
- feature/ - Yangi funksiyalar
- release/ - Release tayyorlash
- hotfix/ - Kritik xatolar
Git Flow jarayoni:
1. Feature development:
# develop dan yangi feature yarating
git checkout develop
git checkout -b feature/user-profile
# Kod yozing, commit qiling
git add .
git commit -m "User profile page qo'shildi"
# develop ga merge qiling
git checkout develop
git merge feature/user-profile
git branch -d feature/user-profile
2. Release tayyorlash:
# Release branch yaratish
git checkout -b release/1.2.0 develop
# Bug fix lar, version yangilash
git commit -m "Version 1.2.0 ga yangilandi"
# main ga merge
git checkout main
git merge release/1.2.0
git tag v1.2.0
# develop ga ham merge
git checkout develop
git merge release/1.2.0
3. Hotfix:
# main dan hotfix yaratish
git checkout main
git checkout -b hotfix/login-error
# Tez xato tuzatish
git commit -m "Login xatosi tuzatildi"
# main ga merge
git checkout main
git merge hotfix/login-error
git tag v1.2.1
# develop ga ham merge
git checkout develop
git merge hotfix/login-error
2. GitHub Flow
Bu - sodda va tez rivojlanish uchun.
main ──────●──────●──────●──────●
\ \ \
feature-1 ●──────●
feature-2 ●──────●
feature-3 ●──────●
Jarayon:
- main dan feature branch yarating
- Kod yozing va commit qiling
- Pull Request oching
- Code review o'tkazing
- main ga merge qiling
- Deploy qiling
# 1. Feature branch yaratish
git checkout main
git checkout -b add-search-feature
# 2. Ishlab, commit qilish
git add .
git commit -m "Search funksiyasi qo'shildi"
git push origin add-search-feature
# 3. GitHub da Pull Request ochish
# 4. Code review
# 5. Merge qilish (GitHub interfeysi orqali)
3. GitLab Flow
Bu - GitHub Flow + environment branch lar.
main ──────●──────●──────●──────●
\ \
production ●──────●──────●──────●
\
staging ●──────●
Environment lar:
- main - development kod
- staging - test environment
- production - live environment
4. Forking Workflow
Bu - open source loyihalar uchun.
Original Repo: main ──●──●──●──●
|
Your Fork: main ──●──●──●
\
Your Feature: feature ●──●
Jarayon:
- Repository ni fork qiling
- Clone qiling
- Feature branch yarating
- Kod yozing
- Your fork ga push qiling
- Original repo ga Pull Request yuboring
Branch Naming Conventions
Feature branches:
feature/user-authentication
feature/payment-integration
feature/admin-dashboard
Bug fixes:
bugfix/login-validation
bugfix/mobile-responsive
hotfix/critical-security-issue
Release branches:
release/1.2.0
release/2.0.0-beta
Semantic naming:
# Type/description format
feat/user-profile
fix/navbar-mobile
docs/api-documentation
style/button-colors
refactor/user-service
test/login-component
Merge vs Rebase
Merge
O'zgarishlarni birlashtiradi va tarix saqlanadi:
git checkout main
git merge feature/login
main ●──●──●──●──●
\ /
feature ●──●──● (merge commit yaratiladi)
Rebase
Branchni qayta yozadi, chiziqli tarix:
git checkout feature/login
git rebase main
git checkout main
git merge feature/login # fast-forward merge
main ●──●──●──●──●──●──● (chiziqli tarix)
Advanced Branch Operations
Interactive Rebase
Commitlarni tahrir qilish:
git rebase -i HEAD~3
# Editor ochiladi:
pick 1a2b3c4 Feature qo'shildi
squash 5d6e7f8 Bug tuzatildi
edit 9g0h1i2 Style yangilandi
Cherry Pick
Bitta commitni boshqa branch ga ko'chirish:
git checkout main
git cherry-pick 1a2b3c4
Branch ochish va yopish
# Remote branch ni track qilish
git checkout --track origin/feature/new-api
# Upstream branch ni o'rnatish
git push -u origin feature/new-api
# Remote branch ni o'chirish
git push origin --delete feature/old-feature
Branch Protection va Rules
GitHub da himoya:
# Branch protection rules
- Require pull request reviews: 2 reviewers
- Dismiss stale reviews: true
- Require review from CODEOWNERS: true
- Require status checks: CI/CD tests
- Require up-to-date branches: true
- Include administrators: true
Pre-commit hooks:
#!/bin/sh
# .git/hooks/pre-commit
# Linting
npm run lint
if [ $? -ne 0 ]; then
echo "❌ Linting failed"
exit 1
fi
# Tests
npm test
if [ $? -ne 0 ]; then
echo "❌ Tests failed"
exit 1
fi
echo "✅ All checks passed"
DevOps uchun Best Practices
1. Kubernetes deployment uchun:
# Environment branch lar
develop → dev-cluster
staging → staging-cluster
main → production-cluster
2. Docker builds:
# Branch name ni image tag sifatida ishlatish
docker build -t myapp:${BRANCH_NAME} .
docker push myapp:${BRANCH_NAME}
3. CI/CD integration:
# GitLab CI
build:
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME .
only:
- main
- develop
- /^feature\/.*$/
Qaysi Strategiyani Tanlash?
Git Flow - agar:
- Katta jamoada ishlasangiz
- Scheduled release larga egasangiz
- Quality control muhim bo'lsa
- Enterprise loyiha bo'lsa
GitHub Flow - agar:
- Kichik jamoada ishlasangiz
- Tez deploy qilishingiz kerak bo'lsa
- Continuous deployment ishlatayotgan bo'lsangiz
- Startup yoki agile loyiha bo'lsa
GitLab Flow - agar:
- Multiple environment lar bo'lsa
- DevOps pipeline complex bo'lsa
- Staging va production alohida bo'lsa
Xulosa
Branch strategies - bu kod sifati va jamoaviy ishlashning asosi:
✅ Parallel development - bir vaqtda ko'p vazifa ✅ Code quality - review va testing ✅ Safe deployment - xavfsiz release ✅ Team collaboration - tartibli hamkorlik ✅ Rollback capability - xatolardan qaytish
DevOps engineer uchun to'g'ri branch strategy tanlash - bu CI/CD pipeline ning muvaffaqiyatli ishlashining kaliti!